package com.nandi.emergencyinspection.utils

import android.app.Activity
import androidx.core.app.ActivityCompat
import java.util.*

/**
 * Date:2018/9/5
 * Time:上午9:37
 * @author qingsong
 */
class SxPermissionsTool {

    class Builder(private val mActivity: Activity) {
        private val permissionList: MutableList<String>

        init {
            this.permissionList = ArrayList()
        }

        fun addPermission(permission: String): Builder {
            if (!this.permissionList.contains(permission)) {
                this.permissionList.add(permission)
            }

            return this
        }

        fun initPermission(): List<String> {
            val list = ArrayList<String>()
            val var2 = this.permissionList.iterator()

            while (var2.hasNext()) {
                val permission = var2.next()
                if (ActivityCompat.checkSelfPermission(this.mActivity, permission) != 0) {
                    list.add(permission)
                }
            }

            if (list.size > 0) {
                ActivityCompat.requestPermissions(this.mActivity, list.toTypedArray() as Array<String>, 1)
            }

            return list
        }
    }

   companion object {

        fun with(activity: Activity): Builder {
            return Builder(activity)
        }
    }
}
